package com.mvc.demo.bean;

import lombok.Data;
import org.hibernate.validator.constraints.Range;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.Valid;
import javax.validation.constraints.*;
import java.util.Date;

/**
 * @author H
 * @date 2023/1/7
 */
@Data
public class ValidatorPojo {

    @NotNull(message = "id不能为空", groups = AddGroup.class)
    private Long id;

    @Future(message = "需要一个将来日期")
    // @Past(message = "需要一个过去的日期")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @NotNull(message = "date不能为空")
    private Date date;

    @NotNull(message = "doubleValue不能为空")
    @DecimalMin("0.1")
    @DecimalMax("100")
    private Double doubleValue;

    @Min(value = 1, message = "最小值为1")
    @Max(value = 7, message = "最大值为7")
    @NotNull(message = "integer不能为空")
    private Integer integer;

    @Range(min = 1, max = 88, message = "范围为1 - 88")
    private Long range;

    @Email(message = "邮箱格式有误")
    private String email;

    @Size(min = 20, max = 30, message = "字符串长度要求20 - 30 之间")
    private String size;

    @Valid
    @NotNull(message = "subValidator不能为空", groups = AddGroup.class)
    private SubValidator subValidator;

}

@Data
class SubValidator {
    @NotBlank(message = "子验证器name不能为空", groups = AddGroup.class)
    private String name;
    @NotNull(message = "子验证器number不能为空", groups = AddGroup.class)
    private Integer number;
}
